package net.cyan.commons.pool.socket;

import net.cyan.commons.log.Log;

import java.net.ServerSocket;

/**
 * <p>Title: </p>
 * <p>Description: </p>
 * <p>Copyright: Copyright (c) 2006</p>
 * <p>Company: </p>
 *
 * @author ccs
 * @version 1.0
 */

public abstract class SocketServlet implements SocketDisposer
{
    private int max = -1;

    private int init;

    private int optimize = -1;

    private int wait = -1;

    private Log log;

    private String name;

    private int timeout;

    private SocketThreadPool pool;

    protected SocketServlet(String name)
    {
        this.name = name;
    }

    public final int getInit()
    {
        return init;
    }

    public final void setInit(int init)
    {
        this.init = init;
    }

    public final Log getLog()
    {
        return log;
    }

    public final void setLog(Log log)
    {
        this.log = log;
    }

    public final int getMax()
    {
        return max;
    }

    public final void setMax(int max)
    {
        this.max = max;
    }

    public final String getName()
    {
        return name;
    }

    public final int getOptimize()
    {
        return optimize;
    }

    public final void setOptimize(int optimize)
    {
        this.optimize = optimize;
    }

    public final int getWait()
    {
        return wait;
    }

    public final void setWait(int wait)
    {
        this.wait = wait;
    }

    protected void startChannel(int port) throws Exception
    {
        pool = new SocketThreadPool(name, init, max, optimize, wait, timeout, log, this);
        pool.startChannel(port);
    }

    protected void startSocket(ServerSocket socket) throws Exception
    {
        pool = new SocketThreadPool(name, init, max, optimize, wait, timeout, log, this);
        pool.startSocket(socket);
    }

    protected void startSocket(int port) throws Exception
    {
        startSocket(new ServerSocket(port));
    }

    protected final SocketThreadPool getPool()
    {
        return pool;
    }

    public final int getTimeout()
    {
        return timeout;
    }

    public final void setTimeout(int timeout)
    {
        this.timeout = timeout;
    }
}